import React, { FC, useEffect } from "react";
import { Form, Input, Select, Checkbox } from "antd";
import { QuestionTitleType } from "./type";

const PropsComponent: FC<QuestionTitleType> = (props) => {
  const { level, title, iscenter, onchange, disabled = false } = props;
  const [form] = Form.useForm();
  //监听标题数据的变化

  useEffect(() => {
    form.setFieldsValue({ level, title, iscenter });
  }, [level, title, iscenter]);
  function handleValueChange() {
    if (onchange) {
      onchange(form.getFieldsValue());
    }
  }
  return (
    <Form layout="vertical" initialValues={{ level, title, iscenter }} form={form} onValuesChange={handleValueChange} disabled={disabled}>
      <Form.Item label="标题" name="title" rules={[{ required: true, message: "请输入标题" }]}>
        <Input />
      </Form.Item>
      <Form.Item label="量级" name="level">
        <Select
          options={[
            { value: 1, text: 1 },
            { value: 2, text: 2 },
            { value: 3, text: 3 },
          ]}
        ></Select>
      </Form.Item>
      <Form.Item name="iscenter" valuePropName="checked">
        <Checkbox>是否居中</Checkbox>
      </Form.Item>
    </Form>
  );
};

export default PropsComponent;
